* IMPORT DATA 

import excel "PathstoPower_individuallevel_v1.0.xlsx", firstrow clear

cd Working Directory

*** Creating Figure 4: Where do cabinet members have working-class occupations before entering politics?

* Creating destringed versions of variables
destring year, gen(year_nostring)
destring core, gen(core_nostring)

* Creating binary class variable
fre classoccupation
gen WC = 1 if classoccupation=="3. Working class" 
replace WC = 0 if classoccupation=="1. Upper class/upper middle class"
replace WC = 0 if classoccupation=="2. Middle class/lower middle class"
replace WC = 0 if classoccupation=="4. Uncodeable/no class"

tab WC classoccupation, missing

* Creating share of WC ministers by year and country
bysort year country_isocode: egen WC_share=mean(WC)


* Somewhere to save figures - replace with your own place
cd "Output"

 // Creating subplot for Norway
capture drop upper
gen upper = 0.25
twoway  line upper year_nostring if inrange(year_nostring, 1971, 1972), recast(area) color(gs14) base(0) || ///
		line upper year_nostring if inrange(year_nostring, 1973, 1981), recast(area) color(gs14) base(0) || ///
		line upper year_nostring if inrange(year_nostring, 1986, 1989), recast(area) color(gs14) base(0) || ///
		line upper year_nostring if inrange(year_nostring, 1990, 1997), recast(area) color(gs14) base(0) || ///
		line upper year_nostring if inrange(year_nostring, 2000, 2001), recast(area) color(gs14) base(0) || ///
		line upper year_nostring if inrange(year_nostring, 2005, 2013), recast(area) color(gs14) base(0) || ///
		line WC_share year_nostring if country_isocode=="NOR" & year_nostring>1965 & core_nostring==1, ytitle("Share WC ministers") xlab(1966(4)2021, angle(45)) xtitle("") title("Norway") legend(off) note("Shaded areas indicate Labour-led governments")
graph save norway.gph, replace
graph export norway.png, replace			
		
* Creating subplot for USA
line WC_share year_nostring if country_isocode=="USA" & year_nostring>1965 & core_nostring==1, ytitle("Share WC ministers") xlab(1966(4)2021, angle(45)) xtitle("") title("USA")  
graph save usa.gph, replace
graph export usa.png, replace		

* Creating Figure 4: Combining subplots for Norway and USA	
graph combine norway.gph usa.gph, ycommon
graph save Figure4.gph, replace 
graph export Figure4.png, replace		
